import React, {useEffect, useState} from "react";
import {Center, ScrollView, View, Text} from "native-base";
import {StyleSheet} from "react-native";
import {NewHeader} from "./newHeader";

export const NewDictionaries = ({route, navigation}) => {
    const [contentMaps, setContentMaps] = useState([]);
    useEffect(()=>{
        const contentMap=[
            {
                name:'字源',
                noShowName:'字源',
                content:{
                    laiyuan:[],
                    name:[],
                    zuozhe:[],
                    photo1:[],
                }
            },
            {
                name:'东周鸟篆',
                noShowName:'東周鳥篆文字編',
                content:{
                    laiyuan:[],
                    name:[],
                    zuozhe:[],
                    photo1:[],
                }
            },
            {
                name:'金文字典',
                noShowName:'金文编',
                content:{
                    laiyuan:[],
                    name:[],
                    zuozhe:[],
                    photo1:[],
                }
            },
            {
                name:'古玺文编',
                noShowName:'古玺文编',
                content:{
                    laiyuan:[],
                    name:[],
                    zuozhe:[],
                    photo1:[],
                }
            },
            {
                name:'战国文字字典',
                noShowName:'战国古文字典',
                content:{
                    laiyuan:[],
                    name:[],
                    zuozhe:[],
                    photo1:[],
                }
            },
            {
                name:'秦印字典',
                noShowName:'秦印文字彙編',
                content:{
                    laiyuan:[],
                    name:[],
                    zuozhe:[],
                    photo1:[],
                }
            },
            {
                name:'秦汉合辑',
                noShowName:'秦汉印章封泥文字编.',
                content:{
                    laiyuan:[],
                    name:[],
                    zuozhe:[],
                    photo1:[],
                }
            },
            {
                name:'漢印字典',
                noShowName:'漢印文字徵',
                content:{
                    laiyuan:[],
                    name:[],
                    zuozhe:[],
                    photo1:[],
                }
            },
            {
                name:'秦汉南北朝官印征存.',
                noShowName:'秦汉南北朝官印征存.',
                content:{
                    laiyuan:[],
                    name:[],
                    zuozhe:[],
                    photo1:[],
                }
            },
            {
                name:'篆刻字典',
                noShowName:'篆刻字典，中國篆刻大辭典',
                content:{
                    laiyuan:[],
                    name:[],
                    zuozhe:[],
                    photo1:[],
                }
            },
            {
                name:'篆刻反字字典',
                noShowName:'篆刻反字字典',
                content:{
                    laiyuan:[],
                    name:[],
                    zuozhe:[],
                    photo1:[],
                }
            },
            {
                name:'鸟虫篆字典',
                noShowName:'鸟虫篆速查手册',
                content:{
                    laiyuan:[],
                    name:[],
                    zuozhe:[],
                    photo1:[],
                }
            },
            {
                name:'古陶字典',
                noShowName:'古陶文字徵',
                content:{
                    laiyuan:[],
                    name:[],
                    zuozhe:[],
                    photo1:[],
                }
            },
        ];
        const msg = route.params.datas;
        const photos = msg[0].replace(/\'/g, "").replace(/\(/g, "").replace(/\[/g, "").replace(/\]/g, "").split(",");
        const laiyuan = msg[1].replace(/\'/g, "").replace(/\[/g, "").replace(/\]/g, "").split(",");
        const zuozhe = msg[3].replace(/\'/g, "").replace(/\[/g, "").replace(/\]/g, "").split(",");
        const name = msg[4].replace(/\'/g, "").replace(/\[/g, "").replace(/\]/g, "").split(",");
        let noShowName=['字源', '東周鳥篆文字編', '金文编', '古玺文编', '战国古文字典', '秦印文字彙編', '秦汉印章封泥文字编', '漢印文字徵', '秦汉南北朝官印征存', '篆刻字典', '篆刻反字字典', '鸟虫篆速查手册', '古陶文字徵'];
        let ten='中國篆刻大辭典';
        for(let i=0;i<name.length;i++){
            if(noShowName.indexOf(name[i].trim())!==-1){
                contentMap[noShowName.indexOf(name[i].trim())].content.laiyuan.push(laiyuan[i].trim())
                contentMap[noShowName.indexOf(name[i].trim())].content.name.push(name[i].trim())
                contentMap[noShowName.indexOf(name[i].trim())].content.zuozhe.push(zuozhe[i].trim())
                contentMap[noShowName.indexOf(name[i].trim())].content.photo1.push(photos[i].trim())
            }else{
                if(name[i]===ten){
                    contentMap[9].content.laiyuan.push(laiyuan[i].trim())
                    contentMap[9].content.name.push(name[i].trim())
                    contentMap[9].content.zuozhe.push(zuozhe[i].trim())
                    contentMap[9].content.photo1.push(photos[i].trim())
                }
            }
        }
        setContentMaps(contentMap);
    }, [route.params.datas])
    return <ScrollView style={styles.Vessels}>
        <Center _text={{fontSize: 20}}>{route.params.tempIpt}</Center>
        <Center>--字典详情--</Center>
        <Center _text={{fontSize: 12, color: '#696969'}}>(如有侵权，请即刻联系scut2459309859, 立删)</Center>
        {
            contentMaps.map((item, index) => {
                return (
                    <View key={index}>
                        {
                            item.content.laiyuan.length !== 0 &&
                            <NewHeader navigation={navigation} msg={item}></NewHeader>
                        }
                    </View>
                )
            })
        }
    </ScrollView>;
};

const styles=StyleSheet.create({
    Vessels:{
        width:'100%',
        height:'100%',
        padding:20,
        backgroundColor:'#fff'
    },
    header:{
        marginBottom:10
    }
})